package com.swingson.componentprocessor.impl;

import com.swingson.SwingsonGui;
import com.swingson.componentprocessor.BaseProcessor;
import com.swingson.jsonparser.JsonObject;
import java.awt.Component;
import java.awt.Container;
import javax.swing.JComponent;
import javax.swing.JScrollPane;

public class JScrollPaneProcessor extends BaseProcessor {
    
    @Override
    public JComponent createComponent(JsonObject jsonElement, JComponent parent, SwingsonGui gui) {
        JScrollPane scroll = new JScrollPane();
        scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        return scroll;
    }
    
    @Override
    public Class[] getProcessingClass() {
        return new Class[]{JScrollPane.class};
    }
    
    @Override
    public void addCompomentToThis(Container parent, Component child, Object layoutParameter) {
        if (layoutParameter != null) {
            ((JScrollPane) parent).getViewport().add(child, layoutParameter);
        } else {
            ((JScrollPane) parent).getViewport().add(child);
        }
    }
}
